package db_meta

import (
	"engine/db"
	"gitee.com/ameise84/e3utils/str_conv"
	jsoniter "github.com/json-iterator/go"
)

func init() {
	db.RegisterTableMetaFactory(StatAutoCtrlFactory)
}

func StatAutoCtrlFactory() db.TableMeta {
	return &StatAutoCtrl{}
}

type StatAutoCtrl struct {
	CtrlID         uint32 `gorm:"-"`
	UserID         uint64 `json:"id" form:"id" gorm:"primarykey;column:id"` // 平台ID
	TotalTimes     int64  `json:"total_times" form:"total_times" gorm:"column:total_times"`
	TodayTimes     int64  `json:"today_times" form:"today_times" gorm:"column:today_times"`
	LastModifyTime int64  `json:"last_modify_time" form:"last_modify_time" gorm:"column:last_modify_time"`
}

func (v *StatAutoCtrl) BaseTableName() string {
	return "stat_auto_ctrl"
}

func (v *StatAutoCtrl) TableName() string {
	return v.BaseTableName() + "_" + str_conv.ToString(v.CtrlID)
}

func (v *StatAutoCtrl) ID() string {
	return str_conv.ToString(v.UserID)
}

func (v *StatAutoCtrl) MarshalBinary() (data []byte, err error) {
	return jsoniter.Marshal(v)
}

func (v *StatAutoCtrl) UnmarshalBinary(data []byte) error {
	return jsoniter.Unmarshal(data, v)
}
